import { ColumnsRenderFun, DictionaryRenderFun, formatDecimal } from '../../Acommon';
import { stateOfRendering } from '../common/Format';

// 排序
const getSorter = (prev: Record<string, any>, next: Record<string, any>): number => (prev > next ? 1 : -1);
/**
 * @getMaterialTableColumns
 * @description 物料弹窗表格信息
 */
const getMaterialTableColumns = (): Record<string, any>[] => {
  return [
    {
      title: '物料名称',
      dataIndex: 'fullName',
      key: 'fullName',
      visible: true,
      width: 170,
      fixed: 'left',
      unDrag: false,
      sorter: (a: any, b: any) => getSorter(a?.fullName, b?.fullName),
      render: (text: string | null) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '物料类型',
      dataIndex: 'materialTypeName',
      key: 'materialTypeName',
      visible: true,
      width: 120,
      sorter: (a: any, b: any) => getSorter(a?.materialTypeName, b?.materialTypeName),
      render: (text: string | null) => DictionaryRenderFun({ text, isTooltip: true }),
    },
    {
      title: '规格要求（参数）', // needParams[需求物料表中]  specInfo[物料表中]
      dataIndex: 'needParams',
      key: 'needParams',
      visible: true,
      width: 180,
      sorter: (a: any, b: any) => getSorter(a?.needParams, b?.needParams),
      render: (text: string | null) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '规格型号',
      dataIndex: 'modelNum',
      key: 'modelNum',
      visible: true,
      width: 150,
      sorter: (a: any, b: any) => getSorter(a?.modelNum, b?.modelNum),
      render: (text: string | null) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '物料状态', //0：起草 1：审核中 2：有效 3：作废
      dataIndex: 'state',
      key: 'state',
      visible: true,
      width: 150,
      unDrag: false,
      sorter: (a: any, b: any) => (a?.state > b?.state ? 1 : -1),
      render: (text: number | null) => stateOfRendering(text),
    },
    {
      title: '量化单位',
      dataIndex: 'unitBusinessName',
      key: 'unitBusinessName',
      visible: true,
      width: 150,
      sorter: (a: any, b: any) => getSorter(a?.unitBusiness, b?.unitBusiness),
      render: (text: string | null) => DictionaryRenderFun({ text }),
    },
    {
      title: '参考单价（元）',
      dataIndex: 'unitPrice',
      key: 'unitPrice',
      visible: true,
      width: 200,
      sorter: (a: any, b: any) => getSorter(a?.unitPrice, b?.unitPrice),
      render: (text: string | null) => <span>{formatDecimal(text)}</span>,
    },
    {
      title: '物料简介',
      dataIndex: 'paramsInfo',
      key: 'paramsInfo',
      visible: true,
      width: 180,
      sorter: (a: any, b: any) => getSorter(a?.paramsInfo, b?.paramsInfo),
      render: (text: string | null) => ColumnsRenderFun({ text, isTooltip: true, wordNum: 100 }),
    },
    // {
    //   title: '物料编码',
    //   dataIndex: 'materialNum',
    //   key: 'materialNum',
    //   visible: true,
    //   width: 170,
    //   unDrag: true,
    //   sorter: (a: any, b: any) => (a?.id > b?.id ? 1 : -1),
    //   render: (text: string) => renderOverflowText(text, true)
    // },
    // {
    //   title: '供货分类',
    //   dataIndex: 'supplyTypeName',
    //   key: 'supplyTypeName',
    //   visible: true,
    //   width: 120,
    //   sorter: (a: any, b: any) => getSorter(a?.supplyTypeName, b?.supplyTypeName),
    //   render: (text: string) => renderOverflowText(text, true),
    // },
    // {
    //   title: '物料状态', //0：起草 1：审核中 2：有效 3：无效
    //   dataIndex: 'state',
    //   key: 'state',
    //   visible: true,
    //   width: 120,
    //   unDrag: false,
    //   sorter: (a: any, b: any) => getSorter(a?.state, b?.state),
    //   render: (text: number | null) => {
    //     return (
    //       <Tooltip>
    //         <span className={pageStyles['over-flow-hidden']}>{stateOfRendering(text)}</span>
    //       </Tooltip>
    //     );
    //   },
    // },
    // {
    //   title: '审核状态',
    //   dataIndex: 'signState',
    //   key: 'signState',
    //   visible: true,
    //   width: 120,
    //   unDrag: false,
    //   sorter: (a: any, b: any) => getSorter(a?.signState, b?.signState),
    //   render: (text: number | null) => {
    //     return (
    //       <Tooltip>
    //         <span className={pageStyles['over-flow-hidden']}>{signStateOfRendering(text)}</span>
    //       </Tooltip>
    //     );
    //   },
    // },
    // {
    //   title: '物料品牌',
    //   dataIndex: 'brandTypeName',
    //   key: 'brandTypeName',
    //   visible: true,
    //   width: 150,
    //   sorter: (a: any, b: any) => getSorter(a?.brandType, b?.brandType),
    //   render: (text: string) => renderOverflowText(text),
    // },
    // {
    //   title: '行政区域',
    //   dataIndex: 'provinceCode',
    //   key: 'provinceCode',
    //   visible: true,
    //   width: 150,
    //   render: (_: string | null, record: Record<string, any>) => {
    //     const newText = renderRegionText(record)
    //     return (
    //       <Tooltip title={tooltipLength(newText, 100)}>
    //         <span className={pageStyles['over-flow-hidden']}>
    //           {newText ? newText : '--'}
    //         </span>
    //       </Tooltip>
    //     );
    //   },
    // },
    // {
    //   title: '详细地址',
    //   dataIndex: 'addressInfo',
    //   key: 'addressInfo',
    //   visible: true,
    //   width: 240,
    //   sorter: (a: any, b: any) => getSorter(a?.addressInfo, b?.addressInfo),
    //   render: (text: string) => renderOverflowText(text),
    // },
  ];
};

export { getMaterialTableColumns };
